package com.sgb.kjwl.viewmodel.home;

import android.text.TextUtils;

import androidx.databinding.ObservableField;
import com.google.gson.reflect.TypeToken;
import com.sgb.auction.base.BaseApi;
import com.sgb.auction.entity.AuctionListEntity;
import com.sgb.auction.entity.PublishListBean;
import com.sgb.auction.entity.RequestBean;
import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.pick.TenderAllListEntity;
import com.sgb.kjwl.model.entity.pick.TenderAllListNewEntity;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.BiddingEntity;
import com.sgb.kjwl.model.entity.PickListUploadEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.ProjectBuyEntity;
import com.sgb.kjwl.model.entity.TenderListEntity;
import com.sgb.kjwl.model.entity.pick.PickInfoListEntity;
import com.sgb.kjwl.model.entity.pick.PreNoticeItemEntity;
import com.sgb.kjwl.model.entity.pick.TenderBidderListEntity;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.HomeRepertory;
import com.swgk.core.mmkvutil.CacheMarker;
import com.sgb.kjwl.view.ui.fragment.home.BiddingSignUpFragment;
import com.sgb.zhaocai.entity.LabourWorkListEntity;
import com.sgb.zhaocai.entity.LeaseNeedListEntity;
import com.sgb.zhaocai.entity.MaterialListEntity;
import com.sgb.zhaocai.entity.ProjectListEntity;
import com.sgb.zhaocai.entity.SubpackagePlanListEntity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.mmkvutil.DatalUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class BiddingSignUpModel extends BaseViewModel {
    public HomeRepertory repertory;
    private BiddingSignUpFragment fragment;
    private int page = 1;
    private Map map;
    public ObservableField<PickListUploadEntity> listEntity1 = new ObservableField<>(new PickListUploadEntity());
    public ObservableField<PickListUploadEntity> listEntity2 = new ObservableField<>(new PickListUploadEntity());
    public ObservableField<PickListUploadEntity> listEntity3 = new ObservableField<>(new PickListUploadEntity());
    public ObservableField<PickListUploadEntity> listEntity4 = new ObservableField<>(new PickListUploadEntity());
    public ObservableField<PickListUploadEntity> listEntity5 = new ObservableField<>(new PickListUploadEntity());
    private final PickListUploadEntity entity;
    private boolean isCache;
    private String longitude;
    private String latitude;

    public BiddingSignUpModel(BiddingSignUpFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
        entity = new PickListUploadEntity();
    }

    /**
     * 正在报名
     *
     * @param typeNo
     * @param b
     */
    public void getSignUpList(String typeNo, boolean b, int position, int mItemType, boolean isRefresh) {
        map = new HashMap();
        page = b ? page + 1 : 1;
//        map.put("areacode", repertory.getAreaCode());
        map.put("comName", "");
        map.put("limit", 3);
        map.put("page", page);
        if (!"".equals(typeNo) && typeNo != null)
            map.put("type", typeNo);
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }

        if (0 == fragment.getPosition() && page == 1 && typeNo.equals("0")) {
            Type type = new TypeToken<List<TenderListEntity>>() {
            }.getType();
            if (!isRefresh) {
                isCache = getCacheData(b, CacheMarker.SignUpList + mItemType, type, false, page);
                if (isCache) {
                    return;
                }
            }
        }
        APIManager.getInstance().getPickAPI().tenderApplyingList(map).enqueue(new ICallBack<BaseEntity<List<TenderListEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<TenderListEntity>> data) {
                if (data == null || data.getState() == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (0 == fragment.getPosition() && typeNo.equals("0")) {
                        setCacheData(data.getData(), b, CacheMarker.SignUpList + mItemType, false, page, isCache);
                    } else {
                        fragment.showList(data.getData(), b);
                    }
                }
            }
        });
    }

    /**
     * 招标报名 type
     * 获取竞价采购 type
     * 招标大厅type数据
     */
    public void tenderNewTypeList(int mItemType, boolean isRefresh) {
        Type type = new TypeToken<List<PickSelectEntity>>() {
        }.getType();
        isCache = getCacheData(false, CacheMarker.SignUpType, type, true, 1);
        if (isRefresh || !isCache) {
            APIManager.getInstance().getPickAPI().tenderNewTypeList().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
                @Override
                public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                    if (data == null || data.getState() == null) {
                        fragment.setTypeDatas(new ArrayList<>());
                        return;
                    }
                    setCacheData(data.getData(), false, CacheMarker.SignUpType, true, 1, isCache);
                }
            });
        }
    }

    /**
     * 竞价采购列表
     *
     * @param typeNo
     * @param b
     */
    public void getCompetitionList(String typeNo, boolean b, int position, int mItemType, boolean isRefresh) {
        map = new HashMap();
        page = b ? page + 1 : 1;
        map.put("limit", 3);
        map.put("page", page);
        if (!"".equals(typeNo) && typeNo != null)
            map.put("type", typeNo);
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (0 == fragment.getPosition() && page == 1 && "0".equals(typeNo)) {
            Type type = new TypeToken<List<BiddingEntity>>() {
            }.getType();
            if (!isRefresh) {
                isCache = getCacheData(b, CacheMarker.SignUpList + mItemType, type, false, page);
                if (isCache) {
                    return;
                }
            }
        }
        APIManager.getInstance().getPickAPI().getBiddingList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<BiddingEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<BiddingEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), b, CacheMarker.CompetitionList + mItemType, false, page, isCache);
                }
            }
        });
    }

    public void getUrlSetting(String id) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("competitivePurchase").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    MLog.d("api", "H5跳转链接  " + url);
                    fragment.getUrl(url);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getUrlSettingSj(String id) {
        APIManager.getInstance().getPickAPI().getUrlSetting("tenderdetails").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    fragment.getUrl(url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * 中标列表
     *
     * @param b
     */
    public void getWinningTheBidData(boolean b, int position, int mItemType, boolean isRefresh) {
        Map map = new HashMap();
        page = b ? page + 1 : 1;
        map.put("limit", 3);
        map.put("page", page);
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        Type type = new TypeToken<List<PreNoticeItemEntity>>() {
        }.getType();
        if (!isRefresh) {
            isCache = getCacheData(b, CacheMarker.BidList + mItemType, type, false, page);
            if (isCache) {
                return;
            }
        }
        APIManager.getInstance().getPickAPI().getBidedList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<PreNoticeItemEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<PreNoticeItemEntity>>> data) {
                if (data == null) return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), b, CacheMarker.BidList + mItemType, false, page, isCache);
                }
            }
        });
    }

    //招标预告的数据列表
    public void getBiddingListData(String type, boolean isLoadMore) {
        Map map = new HashMap();
        page = isLoadMore ? page + 1 : 1;
        map.put("limit", 3);
        map.put("page", page);
        map.put("sortMethod", 1);
        if (!TextUtils.isEmpty(type)) {
            map.put("type", type);
        }
        APIManager.getInstance().getPickAPI().getPreBiddingList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<PreNoticeItemEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<PreNoticeItemEntity>>> data) {
                if (data == null) return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showList(data.getData().getList(), isLoadMore);
                }
            }
        });
    }

    /**
     * 招采需求查询分类
     */
    public void getFilterTypeDemandForecast(int mItemType, boolean isRefresh) {
        Type type = new TypeToken<List<DictEntity3>>() {
        }.getType();
        isCache = getCacheData(false, CacheMarker.PickRequireType + mItemType, type, true, 1);
        if (isRefresh || !isCache) {
            APIManager.getInstance().getPickAPI().getPickRequireType().enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                @Override
                public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                    if (data == null) return;
                    if (data.getState().equals(APIManager.RESPONSE_OK)) {
                        if (data.getData().size() != 0) {
                            setCacheData(data.getData(), false, CacheMarker.PickRequireType + mItemType, true, 1, isCache);
                        }
                    }
                }
            });
        }
    }

    //工程招采列表
    public void getList1(boolean isLoadMore, int position, String areaCode, int mItemType, boolean isRefresh) {
        page = isLoadMore ? page + 1 : 1;
//        listEntity1.get().setAreaCode(areaCode);
        //listEntity1.get().setPageNum(page);
        //listEntity1.get().setPageSize(3);
        map = new HashMap();
        map.put("page", page);
        map.put("limit", 3);
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        Type type = new TypeToken<List<ProjectBuyEntity>>() {
        }.getType();
        isCache = getCacheData(isLoadMore, CacheMarker.ProjectList + mItemType, type, false, page);
        APIManager.getInstance().getPickAPI().getProjectLists(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<ProjectListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<ProjectListEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.ProjectList + mItemType, false, page, isCache);
                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    //材料列表
    public void getList2(boolean isLoadMore, int position, String areaCode, int mItemType, boolean isRefresh) {
        page = isLoadMore ? page + 1 : 1;
//        listEntity2.get().setPageNum(page);
//        listEntity2.get().setPageSize(3);
//        listEntity2.get().setAreaCode(areaCode);
        map = new HashMap();
        map.put("page", page);
        map.put("limit", 3);
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        Type type = new TypeToken<ProListEntity<List<ProjectBuyEntity>>>() {
        }.getType();
        isCache = getCacheData(isLoadMore, CacheMarker.MaterialList + mItemType, type, false, page);
        APIManager.getInstance().getPickAPI().getMaterialList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<MaterialListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<MaterialListEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.MaterialList + mItemType, false, page, isCache);
                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    //租赁列表
    public void getList3(boolean isLoadMore, int position, String areaCode, int mItemType, boolean isRefresh) {
        page = isLoadMore ? page + 1 : 1;
        Map map = new HashMap();
        map.put("page", page);
        map.put("limit", 3);
//        map.put("areaCode", areaCode);
//        map.put("cityNo",  listEntity3.get().getCityNo());
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        Type type = new TypeToken<ProListEntity<List<ProjectBuyEntity>>>() {
        }.getType();
        isCache = getCacheData(isLoadMore, CacheMarker.EquipmentList + mItemType, type, false, page);
        APIManager.getInstance().getPickAPI().getLeaseNeedList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseNeedListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseNeedListEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.EquipmentList + mItemType, false, page, isCache);

                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    //劳务列表
    public void getList4(boolean isLoadMore, int position, String areaCode, int mItemType, boolean isRefresh) {
        page = isLoadMore ? page + 1 : 1;
        Map map = new HashMap();
        map.put("page", page);
        map.put("limit", 3);
//        map.put("areaCode", areaCode);
//        map.put("cityNo", listEntity4.get().getCityNo());
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        Type type = new TypeToken<ProListEntity<List<ProjectBuyEntity>>>() {
        }.getType();
        isCache = getCacheData(isLoadMore, CacheMarker.LaborSubcontract + mItemType, type, false, page);
        APIManager.getInstance().getPickAPI().getLabourWorkList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<LabourWorkListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LabourWorkListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.LaborSubcontract + mItemType, false, page, isCache);
                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    //工程施工列表
    public void getList5(boolean isLoadMore, int position, String areaCode, int mItemType, boolean isRefresh) {
        page = isLoadMore ? page + 1 : 1;
        Map map = new HashMap();
        map.put("page", page);
        map.put("limit", 3);
//        map.put("areaCode", areaCode);
//        map.put("cityNo", listEntity5.get().getCityNo());
//        map.put("typeNo", null);
//        map.put("type", listEntity5.get().getType());
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        Type type = new TypeToken<ProListEntity<List<ProjectBuyEntity>>>() {
        }.getType();
        isCache = getCacheData(isLoadMore, CacheMarker.EngineSubcontract + mItemType, type, false, page);
        APIManager.getInstance().getPickAPI().getSubpackagePlanList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<SubpackagePlanListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<SubpackagePlanListEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.EngineSubcontract + mItemType, false, page, isCache);

                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    /**
     * 招标信息列表数据
     *
     * @param typeNo
     * @param isLoadMore
     */
    public void getBiddingInformationList(String typeNo, int position, boolean isLoadMore, int mItemType) {
        page = isLoadMore ? page + 1 : 1;
        Map map = new HashMap();
//        if (!TextUtils.isEmpty(areacode))
//            map.put("areacode", areacode);
//        if (!TextUtils.isEmpty(cityNo))
//            map.put("city", cityNo);
        map.put("limit", 3);
        map.put("page", page);
//        map.put("name", search);
        if (!TextUtils.isEmpty(typeNo)) {
            if (typeNo.equals("全部")) {
                typeNo = "";
            }
            map.put("tenderType", typeNo);
        }
        if (!(page == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if ("全部".equals(typeNo)) {
            Type type = new TypeToken<List<PickInfoListEntity>>() {
            }.getType();
            isCache = getCacheData(isLoadMore, CacheMarker.TenderNoticeList + mItemType, type, false, page);
        }
        String finalTypeNo = typeNo;
        APIManager.getInstance().getPickAPI().getPickInfoList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<PickInfoListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<PickInfoListEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (null == data.getData()) {
                    return;
                }
                if (data.getState().equals(AppConstant.REQEUST_SECCUESS)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.TenderNoticeList + mItemType, false, page, isCache);
                }

            }
        });

    }

    /**
     * 标信息列表
     */
    public void getTypeBiddingInformationData(int mItemType, boolean isRefresh) {
        Map map = new HashMap();
//        map.put("areacode", repertory.getAreaCode());
        map.put("keyword", "");
        map.put("name", "");
        Type type = new TypeToken<List<PickSelectEntity>>() {
        }.getType();
        isCache = getCacheData(false, CacheMarker.TenderNoticeType + mItemType, type, true, 1);
        if (isRefresh || !isCache) {
            APIManager.getInstance().getPickAPI().getPickInfoType(map).enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
                @Override
                public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                    if (data == null || data.getState() == null) {
                        return;
                    }

                    if (data.getState().equals(APIManager.RESPONSE_OK)) {
                        setCacheData(data.getData(), false, CacheMarker.TenderNoticeType + mItemType, true, 1, isCache);
                    }
                }
            });
        }
    }

    public void getH5Url(String id) {
        DialogHelper.showProgressDialog(fragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("tenderNoticeDetail").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
//                    String url = "http://192.168.2.49:8067/tenderNoticeDetail" + "?id=" + id;
                    fragment.showUrl(url);
                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    public void getH5Url(String id, String longitudes, String latitudes) {
        DialogHelper.showProgressDialog(fragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("engineeringProject").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                DialogHelper.dismissProgressDialog();
                String webUrl = data.getData().getUrl() + "?id=" + id + "&lng=" + longitudes + "&lat=" + latitudes;
                fragment.showUrl(webUrl);
            }
        });
    }

    public void getWebView(String no) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getUrlSetting("Auctiondetails").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    String webUrl = data.getData().getUrl() + "?no=" + no;
                    BaseApi.startWeb(fragment.getActivity(), webUrl,123456);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getsubpackageplanH5Url( String projectId, String longitudes, String latitudes) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("subcontractPlan").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(APIManager.RESPONSE_OK)){
                    String webUrl = data.getData().getUrl() + "?id=" + projectId + "&lng=" + longitudes + "&lat=" + latitudes;
                    fragment.showUrl(webUrl);
                }else {
                    MToast.showToast(fragment.getContext(),data.getMsg());
                }
            }
        });
    }

    /**
     * 是否有缓存
     */
    public <T> boolean getCacheData(boolean isLoadMore, String mType, Type type, boolean isType, int pos) {
        if (fragment.getPosition() == 0 && pos == 1) {
            Object object = DatalUtils.getInstance().getData(MkvUtils.CacheModular, mType, type);
            if (object != null) {
                List<T> list = (List<T>) object;
                if (isType) {
                    fragment.setTypeDatas(list);
                } else {
                    fragment.showList(list, isLoadMore);
                }
                return true;
            }
        }
        return false;
    }

    /**
     * 是否更新缓存
     */
    public <T> void setCacheData(List<T> dataList, boolean isLoadMore, String mType, boolean isType, int pos, boolean isCache) {
        if (fragment.getPosition() == 0 && pos == 1) {
            String cacheMateialistlHash = DatalUtils.getHashData(MkvUtils.CacheModular, mType);
            //获取从网络请求下来的数据的哈希值
            String mHashNet = DatalUtils.getInstance().strToHashKey(dataList);
            if (!cacheMateialistlHash.equals(mHashNet) || isCache == false) {
                if (isType) {
                    fragment.setTypeDatas(dataList);
                } else {
                    fragment.showList(dataList, isLoadMore);
                }
                DatalUtils.getInstance().putData(MkvUtils.CacheModular, mType, dataList);
            } else {
                if (isType) {
                } else {
                    fragment.showList(dataList, isLoadMore);
                }
            }
        } else {
            if (isType) {
                fragment.setTypeDatas(dataList);
            } else {
                fragment.showList(dataList, isLoadMore);
            }
        }
    }

    public void getWebH5(String id, String modelType) {
        longitude = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID,"");
        latitude = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID,"");
        if (TextUtils.isEmpty(longitude)){
            longitude = "0";
        }
        if (TextUtils.isEmpty(latitude)){
            latitude = "0";
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("engineeringProject").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String webUrl = data.getData().getUrl() + "?id=" + id + "&lng=" + longitude + "&lat=" + latitude +"&type="+modelType;
                    WebViewX5HostActivity.start(fragment.getActivity(), webUrl);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getUrlSettingTender(String id) {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().getUrlSetting("FrontDeskBidding").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    MLog.d("api", "H5跳转链接  " + url);
                    fragment.getUrl(url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * 获取tab页签方法
     */
    public void getAuctionHallTabList() {
        BaseApi.getApi().getAuctionStateSelect().enqueue(new ICallBack<BaseEntity<List<PublishListBean>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PublishListBean>> data) {
                if (data == null || data.getState() == null) {
                    fragment.setTypeDatas(new ArrayList<>());
                    return;
                }
                if (data.getState().equals(BaseApi.RESPONSE_OK)){
                    fragment.setTypeDatas(data.getData());
                }
            }
        });
    }

    /**
     * 拍卖大厅列表
     */
    public void AuctionHallList(String typeNo, boolean isLoadMore) {
        page = isLoadMore ? page + 1 : 1;
        RequestBean requestBean = new RequestBean();
        requestBean.setState(typeNo);
        String longitudes;//经度
        String latitudes;//纬度
        longitudes = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
        latitudes = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
        if (TextUtils.isEmpty(longitudes)) {
            longitudes = "0";
        }
        if (TextUtils.isEmpty(latitudes)) {
            latitudes = "0";
        }
        requestBean.setLocalLat(latitudes);
        requestBean.setLocalLng(longitudes);
        requestBean.page = page;
        requestBean.limit = 6;
        BaseApi.getApi().getAuctionHallList(requestBean).enqueue(new ICallBack<BaseEntity<ListResponse<List<AuctionListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<AuctionListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)) {
                    fragment.showList(data.getData().getList(), isLoadMore);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     *
     * @param mItemType 0 招标公告 2招标大厅
     */
    public void findTenderingEsPage(String typeNo,int mItemType,boolean isLoadMore) {
        page = isLoadMore ? page + 1 : 1;
        map = new HashMap();
        if ("0".equals(typeNo)) {
            typeNo = "";
        }
        map.put("type", typeNo);//类型
        map.put("goodsTypeNo", ""); //类别二级
        map.put("province", ""); //省
        map.put("city", ""); //市
        if (mItemType == 2){
            map.put("queryPosition", 3); //招标大厅
        }else if (mItemType == 0){ //招标公告
            map.put("queryPosition", 5); //招标公告
        }
        map.put("current", page);
        map.put("limit", 3);
        map.put("sortMethod","1"); //排序类型
        map.put("dataSources","0"); //数据来源
        map.put("keyword",""); //搜索关键字
        if (fragment.getPosition() != 0 && fragment.getActivity() != null && !fragment.getActivity().isDestroyed() && !fragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        if (0 == fragment.getPosition() && "".equals(typeNo) && !isLoadMore && page == 0) {
            Type type = new TypeToken<List<TenderListEntity>>() {
            }.getType();
            isCache = getCacheData(!fragment.getIsRefresh(), CacheMarker.TenderBidList + mItemType, type, false, page);
            if (isCache) {
                return;
            }
        }
        queryHomeEsPage(map,isLoadMore,mItemType);
    }

    private void queryHomeEsPage(Map map,boolean isLoadMore,int mItemType){
        APIManager.getInstance().getPickAPI().queryHomeEsPage(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderAllListNewEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderAllListNewEntity>>> data) {
                if (data == null || data.getState() == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.TenderBidList + mItemType, false, page, isCache);
                }
            }
        });
    }
}
